home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / SOUND / SOXSOURCE / sox / h / st < prev    next >
Text File  |  1994-06-05  |  6KB  |  231 lines

  1. /*
  2.  * July 5, 1991
  3.  * Copyright 1991 Lance Norskog And Sundry Contributors
  4.  * This source code is freely redistributable and may be used for
  5.  * any purpose.  This copyright notice must be maintained.
  6.  * Lance Norskog And Sundry Contributors are not responsible for
  7.  * the consequences of using this software.
  8.  */
  9.  
  10. #ifdef VAXC
  11. #define IMPORT  globalref
  12. #define EXPORT  globaldef
  13. /*
  14.  * use the VAX C optimized functions
  15.  */
  16. #define calloc  VAXC$CALLOC_OPT
  17. #define cfree   VAXC$CFREE_OPT
  18. #define free    VAXC$FREE_OPT
  19. #define malloc  VAXC$MALLOC_OPT
  20. #define realloc VAXC$REALLOC_OPT
  21. #else
  22. #define IMPORT  extern
  23. #define EXPORT
  24. #endif
  25.  
  26.  
  27. /*
  28.  * Sound Tools sources header file.
  29.  */
  30.  
  31. #include <stdio.h>
  32.  
  33. #ifdef AMIGA
  34. #include "amiga.h"
  35. #endif /* AMIGA */
  36.  
  37. /*
  38.  * Handler structure for each format.
  39.  */
  40.  
  41. typedef struct format {
  42.     char    **names;    /* file type names */
  43.     int    (*startread)();
  44.     int    (*read)();
  45.     int    (*stopread)();
  46.     int    (*startwrite)();
  47.     int    (*write)();
  48.     int    (*stopwrite)();
  49. } format_t;
  50.  
  51. IMPORT format_t formats[];
  52.  
  53. /* Signal parameters */
  54.  
  55. struct  signalinfo {
  56.     long        rate;        /* sampling rate */
  57.     int        size;        /* word length of data */
  58.     int        style;        /* format of sample numbers */
  59.     int        channels;    /* number of sound channels */
  60. };
  61.  
  62. /* Pipe parameters */
  63.  
  64. struct    pipeinfo {
  65.     FILE    *pout;            /* Output file */
  66.     FILE    *pin;            /* Input file */
  67. };
  68.  
  69. /*
  70.  *  Format information for input and output files.
  71.  */
  72.  
  73. #define    PRIVSIZE    100
  74.  
  75. struct soundstream {
  76.     struct    signalinfo info;    /* signal specifications */
  77.     char    swap;            /* do byte- or word-swap */
  78.     char    seekable;        /* can seek on this file */
  79.     char    *filename;        /* file name */
  80.     char    *filetype;        /* type of file */
  81.     char    *comment;        /* comment string */
  82.     FILE    *fp;            /* File stream pointer */
  83.     format_t *h;            /* format struct for this file */
  84.     char    priv[PRIVSIZE];        /* format's private data area */
  85. };
  86.  
  87. IMPORT struct soundstream informat, outformat;
  88. typedef struct soundstream *ft_t;
  89.  
  90. /* Size field */
  91. #define    BYTE    1
  92. #define    WORD    2
  93. #define    LONG    4
  94. #define    FLOAT    5
  95. #define DOUBLE    6
  96. #define IEEE    7        /* IEEE 80-bit floats.  Is it necessary? */
  97.  
  98. /* Style field */
  99. #define UNSIGNED    1    /* unsigned linear: Sound Blaster */
  100. #define SIGN2        2    /* signed linear 2's comp: Mac */
  101. #define    ULAW        3    /* U-law signed logs: US telephony, SPARC */
  102. #define ALAW        4    /* A-law signed logs: non-US telephony */
  103.  
  104. IMPORT char *sizes[], *styles[];
  105.  
  106. /*
  107.  * Handler structure for each effect.
  108.  */
  109.  
  110. typedef struct {
  111.     char    *name;            /* effect name */
  112.     int    flags;            /* this and that */
  113.     int    (*getopts)();        /* process arguments */
  114.     int    (*start)();        /* start off effect */
  115.     int    (*flow)();        /* do a buffer */
  116.     int    (*drain)();        /* drain out at end */
  117.     int    (*stop)();        /* finish up effect */
  118. } effect_t;
  119.  
  120. IMPORT effect_t effects[];
  121.  
  122. #define    EFF_CHAN    1        /* Effect can mix channels up/down */
  123. #define EFF_RATE    2        /* Effect can alter data rate */
  124. #define EFF_MCHAN    4        /* Effect can handle multi-channel */
  125.  
  126. struct effect {
  127.     char        *name;        /* effect name */
  128.     struct signalinfo ininfo;    /* input signal specifications */
  129.     struct signalinfo outinfo;    /* output signal specifications */
  130.     effect_t     *h;        /* effects driver */
  131.     char        priv[PRIVSIZE];    /* private area for effect */
  132. };
  133.  
  134. typedef struct effect *eff_t;
  135.  
  136. #if defined(__STDC__) || defined(ARM)
  137. #define    P1(x) x
  138. #define    P2(x,y) x, y
  139. #define    P3(x,y,z) x, y, z
  140. #define    P4(x,y,z,w) x, y, z, w
  141. #else
  142. #define P1(x)
  143. #define P2(x,y)
  144. #define P3(x,y,z)
  145. #define P4(x,y,z,w)
  146. #endif
  147.  
  148. /* Utilities to read and write shorts and longs little-endian and big-endian */
  149. unsigned short rlshort(P1(ft_t ft));            /* short little-end */
  150. unsigned short rbshort(P1(ft_t ft));            /* short big-end    */
  151. unsigned short wlshort(P2(ft_t ft, unsigned short us));    /* short little-end */
  152. unsigned short wbshort(P2(ft_t ft, unsigned short us));    /* short big-end    */
  153. unsigned long  rllong(P1(ft_t ft));            /* long little-end  */
  154. unsigned long  rblong(P1(ft_t ft));            /* long big-end     */
  155. unsigned long  wllong(P2(ft_t ft, unsigned long ul));    /* long little-end  */
  156. unsigned long  wblong(P2(ft_t ft, unsigned long ul));    /* long big-end     */
  157. /* Read and write words and longs in "machine format".  Swap if indicated.  */
  158. unsigned short rshort(P1(ft_t ft));
  159. unsigned short wshort(P2(ft_t ft, unsigned short us));
  160. unsigned long  rlong(P1(ft_t ft));
  161. unsigned long  wlong(P2(ft_t ft, unsigned long ul));
  162. /* Utilities to byte-swap values */
  163. unsigned short swapw(P1(unsigned short us));        /* Swap short */
  164. unsigned long  swapl(P1(unsigned long ul));        /* Swap long */
  165.  
  166. IMPORT void report(P2(char *, ...)), fail(P2(char *, ...));
  167.  
  168. #ifdef ARM
  169. IMPORT double sfloor(P1(double x));   /* Hack our way around the flawed */
  170. IMPORT double sceil(P1(double x));    /* UnixLib floor + ceil functions */
  171. #endif
  172.  
  173. typedef    unsigned int u_i;
  174. typedef    unsigned long u_l;
  175. typedef    unsigned short u_s;
  176.  
  177. #define    MAXRATE    50L * 1024            /* maximum sample rate */
  178.  
  179. #if  defined(unix) || defined (__OS2__)
  180. /* Some wacky processors don't have arithmetic down shift, so do divs */
  181. #define LEFT(datum, bits)    (datum << bits)
  182. /* Most compilers will turn this into a shift if they can, don't worry */
  183. /* #define RIGHT(datum, bits)    (datum / (1L << bits)) /* use maybe? */
  184. #define RIGHT(datum, bits)    (datum >> bits)
  185. #else
  186. /* x86 & 68k PC's have arith shift ops and dumb compilers */
  187. #define LEFT(datum, bits)    (datum << bits)
  188. #define RIGHT(datum, bits)    (datum >> bits)
  189. #endif
  190.  
  191. #ifndef    M_PI
  192. #define M_PI    3.14159265358979323846
  193. #endif
  194.  
  195. #if    defined(unix) || defined(AMIGA) || defined (__OS2__) || defined(OS9) || defined(ARM)
  196. #define READBINARY    "r"
  197. #define WRITEBINARY    "w"
  198. #endif
  199. #ifdef    VMS
  200. #define READBINARY      "r", "mbf=16", "ctx=stm"
  201. #define WRITEBINARY     "w", "ctx=stm"
  202. #endif
  203. #ifdef    DOS
  204. #define READBINARY    "rb"
  205. #define WRITEBINARY    "wb"
  206. #endif
  207.  
  208. /* Error code reporting */
  209. #ifdef    QNX
  210. #include <errno.h>
  211. #endif
  212.  
  213. #if defined(unix) || defined(__OS2__)
  214. #include <errno.h>
  215. extern errno;
  216. #if defined(i386) || !defined(__STDC__)
  217. /* usually be a const in stdlib.h ?? */
  218. /* this is turning out to be a headache */
  219. extern char *sys_errlist[];
  220. #define strerror(errno)    sys_errlist[errno]
  221. #endif
  222. #endif
  223.  
  224. #ifdef    __OS2__
  225. #define REMOVE remove
  226. #else
  227. #define REMOVE unlink
  228. #endif
  229.  
  230. /* ummmm??? */
  231.